﻿/*======================================*\
* Author: Vincent
* LastModifyUser: Vincent
* Description:  
* CreateTime： 2012-05
* Remark:  
\*======================================*/
using System;
using System.Drawing;
using System.Windows.Forms;
using AppCode.Domain.Services;

namespace Vincent.AutoCode 
{
    /// <summary>
    /// 主窗体类分部
    /// <remarks>
    /// 与自定义事件相关的分部
    /// </remarks>
    /// </summary>
    public partial class frmMain
    {
        #region 数据初始化事件

        /// <summary>
        /// 树信息加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dbHandler_LoadTreeInfo(object sender, TaskInfoEventArgs e)
        {
            LoadTableToTree(e.msg,e.value);
        }

 

        /// <summary>
        /// 状态信息事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dbHandler_ReportMsgEvent(object sender, TaskInfoEventArgs e)
        {
            WriteStatusInfo(e.msg);
        }

        /// <summary>
        /// 加载任务进度事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dbHandler_ReportTaskProcessEvent(object sender, TaskInfoProcessEventArgs e)
        {
            statusProgressBar.Value = e.Process;
        }

        /// <summary>
        /// 写任务信息到文本框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dbHandler_ReportTaskInfoToTextEvent(object sender, TaskInfoEventArgs e)
        {
            if (e.statecode == 100)
                btnExcute.Enabled = true;
            WriteLogToRichTextBox(e.msg);

        }

        /// <summary>
        /// 开始生成代码文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dbHandler_BeginCreateCodeFile(object sender, EventArgs e)
        {
            string outFilePath = this.txtOutPutFolder.Text.Trim();
            string nameSpaceName = this.txtNameSpace.Text.Trim();
            CodeCreateHandler createCodeHandler = new CodeCreateHandler(outFilePath,nameSpaceName);
            createCodeHandler.ReportLogToTextEvent += new EventHandler<TaskInfoEventArgs>(createCodeHandler_ReportLogToTextEvent);
            createCodeHandler.Create();
        }

        /// <summary>
        /// 生成日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void createCodeHandler_ReportLogToTextEvent(object sender, TaskInfoEventArgs e)
        {
            WriteLogToRichTextBox(e.msg);
        }
        #endregion

        
    }
}
